package com.etc.emsys.controller;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

public class BaseContrller implements Initializable {

    public static Scene pre;

    /**
     * 带回退的跳转
     * @param scene
     * @param url
     * @param title
     * @param data
     */
    public void transform(Scene scene, String url, String title, Object data) {
        try {
            BaseContrller.pre = scene;
            FXMLLoader loader = new FXMLLoader(getClass()
                    .getResource(url));
            BaseMenuController.param = data;
            Parent parent = loader.load();
            Scene newscene = new Scene(parent, 600, 500);
            newscene.setRoot(parent);
            Stage stage = (Stage) scene.getWindow();
            stage.setScene(newscene);
            stage.setTitle(title);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
    @Override
    public void initialize(URL location, ResourceBundle resources) {

    }


    /**
     *
     * @param url
     * @param title
     * @param data
     * @param scene
     */
    public void transformNon(String url, String title, Object data, Scene scene) {
        try {
            BaseContrller.pre = null;
            BaseMenuController.param = null;
            FXMLLoader loader = new FXMLLoader(getClass()
                    .getResource(url));
            Parent parent = loader.load();
            scene.setRoot(parent);
            Stage stage = (Stage) scene.getWindow();
            stage.setScene(scene);
            stage.setTitle(title);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
